"""
通过setter及getter获取与参数
"""


class Student(object):
    def get_score(self):
        return self._score

    def set_score(self, value):
        if not isinstance(value, int):
            raise ValueError('score must be an integer!')
        if value < 0 or value > 100:
            raise ValueError('score must between 0 ~ 100!')
        self._score = value


class StudentProperty(object):

    @property
    def birth(self):
        return self._birth

    @birth.setter
    def birth(self, value):
        self._birth = value

    @property
    def age(self):
        return 2015 - self._birth


if __name__ == '__main__':
    s = Student()
    s.set_score(6)
    print(s.get_score())
    try:
        s.set_score(999)
    except ValueError as e:
        print('Error: ' + str(e))

    s_p = StudentProperty()
    s_p.birth = 1000
    print(s_p.birth)
    print(s_p.age)
